﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jermaine.Cache
{
    public class CacheFactory
    {

        private static readonly String DefaultName = "Default";

        private CacheFactory() { }

        /// <summary>
        /// 获取其他实例
        /// </summary>
        /// <param name="serviceName"></param>
        /// <returns></returns>
        public static ICacheService GetInstance(String serviceName) {
            ICacheService service = null;
            if (ObjectFactory.Exists<ICacheService>(serviceName)) {
                service = ObjectFactory.Get<ICacheService>(serviceName);
            } else {
                service = CacheService.Create();
                ObjectFactory.Put<ICacheService>(serviceName, service);
            }

            return service;
        }

        /// <summary>
        /// 获取默认实例
        /// </summary>
        public static ICacheService Default {
            get {
                return GetInstance(DefaultName);
            }

        }

    }
}
